<?php
namespace app\erp_meixingtiyu\logic;

use app\erp_meixingtiyu\model\TimeTemplate as TimeTemplateModel;

class TimeTemplate
{
    public function deleteTemplate($templateId)
    {
        $time_template = TimeTemplateModel::getTemplateWithArenasById($templateId);
         // 判断是否有正在使用该时段模板，有则不允许删除
        $isEmpty = $time_template->arenas->isEmpty();
        if ($isEmpty) {
            $time_template->together(['arenas'])->delete();
        } else {
            throw new \Exception('有场地正在使用该模板，无法删除！');
        }
    }
}
